package com.lg.cms.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lg.cms.entity.Article;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lg.cms.vo.admin.addArticleVO;
import com.lg.cms.vo.news.ArticleVO;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * <p>
 * 文章表 Mapper 接口
 * </p>
 *
 * @author lg
 * @since 2020-09-21
 */
@Mapper
@PermitAll
public interface ArticleMapper extends BaseMapper<Article>
{
//    @Select("SELECT * FROM user ${ew.customSqlSegment}")
//    List<Article> selectByMyWrapper(@Param(Constants.WRAPPER) Wrapper<Article> userWrapper);
    @Select("SELECT a.*,c.`name` category ,aa.`name` articleType FROM `article` as a,article_type AS aa,category as c WHERE a.category_id=c.id AND a.article_type_id=aa.id AND a.is_delete=0 BETWEEN 1 AND 10  ")
    IPage<addArticleVO> selectAll(@Param("page")IPage<addArticleVO> page, @Param(Constants.WRAPPER) Wrapper<addArticleVO> wa);

    @Select("SELECT a.*,c.`name` category ,aa.`name` articleType FROM `article` as a,article_type AS aa,category as c where a.id=#{ids} and c.id=a.category_id AND aa.id=a.article_type_id ")
    List<addArticleVO> select( @Param(Constants.WRAPPER) Wrapper wa, @Param("ids") Integer id);

    @Select("SELECT a.*,c.`name` category ,aa.`name` articleType FROM `article` as a,article_type AS aa,category as c ${ew.customSqlSegment}  and a.category_id=c.id  AND a.article_type_id=aa.id AND a.is_delete=0 BETWEEN 1 AND 10 ")
    IPage<addArticleVO> selectAlls(@Param("page")IPage<addArticleVO> page,@Param(Constants.WRAPPER) Wrapper wrapper);


    @Select("SELECT * FROM `article` GROUP BY state")
    List<addArticleVO> selectAllS(@Param(Constants.WRAPPER) Wrapper<addArticleVO> queryWrapper);

}
